<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8" style="margin-top:20px">
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          v-hasPermi="['station:selfService:edit']"
          @click="handleAdd"
          >添加自助机</el-button
        >
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="postList">
      <el-table-column width="70" type="index" label="序号" align="center" />
      <el-table-column label="终端号" align="center" prop="terminacode" />
      <el-table-column label="自助机编码" align="center" prop="machinecode" />
      <el-table-column label="地市" align="center" prop="city" />
      <el-table-column label="汽车站" align="center" prop="station" />
      <el-table-column label="汽车站编码" align="center" prop="stationcode" />
      <el-table-column label="汽车站等级" align="center" prop="stationlevel" />
      <el-table-column label="功能" align="center" prop="function" />
      <el-table-column label="厂家" align="center" prop="factory" width="160" />
      <el-table-column label="来源" align="center" prop="source" width="180" />
      <el-table-column
        label="联系人"
        align="center"
        prop="contactpeople"
        width="180"
      />
      <el-table-column
        label="状态"
        align="center"
        prop="sellstatus"
        width="180"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="getParticulars(scope.row)"
            v-hasPermi="['station:selfService:edit']"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['station:selfService:edit']"
            @click="handleUpdate(scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['station:selfService:edit']"
            >配置</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改自助机话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="id:" prop="id" label-width="115px">
              <el-input v-model="form.id" placeholder="请输入" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              label="终端号:"
              prop="terminacode"
              label-width="115px"
            >
              <el-input v-model="form.terminacode" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item
              label="汽车站编码:"
              prop="stationcode"
              label-width="115px"
            >
              <el-input v-model="form.stationcode" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="车站地址:"
              prop="stationaddress"
              label-width="115px"
            >
              <el-input v-model="form.stationaddress" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="地市:" prop="city" label-width="115px">
              <el-input v-model="form.city" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="汽车站等级:"
              prop="stationlevel"
              label-width="115px"
            >
              <el-input v-model="form.stationlevel" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item
              label="自助机编码:"
              prop="machinecode"
              label-width="115px"
            >
              <el-input v-model="form.machinecode" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="IP地址:" prop="ipaddress" label-width="115px">
              <el-input v-model="form.ipaddress" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="汽车站:" prop="station" label-width="115px">
              <el-input v-model="form.station" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安装时间:" prop="settime" label-width="115px">
              <el-input v-model="form.settime" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item
              label="商户号:"
              prop="merchantnum"
              label-width="115px"
            >
              <el-input v-model="form.merchantnum" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="联系人:"
              prop="contactpeople"
              label-width="115px"
            >
              <el-input v-model="form.contactpeople" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="功能:" prop="function" label-width="115px">
              <el-input v-model="form.function" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态:" prop="sellstatus" label-width="115px">
              <el-input v-model="form.sellstatus" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="厂家:" prop="factory" label-width="115px">
              <el-input v-model="form.factory" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工号:" prop="jobnum" label-width="115px">
              <el-input v-model="form.jobnum" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="型号:" prop="machinemodel" label-width="115px">
              <el-input v-model="form.machinemodel" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="登录密码:"
              prop="loginpassword"
              label-width="115px"
            >
              <el-input v-model="form.loginpassword" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="数量:" prop="amount" label-width="115px">
              <el-input v-model="form.amount" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="是否允许售票:"
              prop="isallow"
              label-width="115px"
            >
              <el-select
                v-model="form.isallow"
                clearable
                placeholder="请选择"
                style="width:100%"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="来源:" prop="source" label-width="115px">
              <el-input v-model="form.source" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登录状态:" label-width="115px" prop="islogin">
              <el-select
                v-model="form.islogin"
                clearable
                placeholder="请选择"
                style="width:100%"
              >
                <!-- <template slot-scope="scope"> -->
                <!-- <template> -->
                <!-- {{ scope.row }} -->
                <el-option
                  v-for="item in login"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
                <!-- </template> -->
                <!-- </template> -->
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="备注:" label-width="115px">
              <el-input placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详情弹出框 -->
    <el-dialog
      :title="title"
      :visible.sync="particulars"
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="id:" prop="id" label-width="115px">
              <el-input
                v-model="form.id"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              label="终端号:"
              prop="terminacode"
              label-width="115px"
            >
              <el-input
                v-model="form.terminacode"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item
              label="汽车站编码:"
              prop="stationcode"
              label-width="115px"
            >
              <el-input
                v-model="form.stationcode"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="车站地址:"
              prop="stationaddress"
              label-width="115px"
            >
              <el-input
                v-model="form.stationaddress"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="地市:" prop="city" label-width="115px">
              <el-input
                v-model="form.city"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="汽车站等级:"
              prop="stationlevel"
              label-width="115px"
            >
              <el-input
                v-model="form.stationlevel"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item
              label="终端号:"
              prop="machinecode"
              label-width="115px"
            >
              <el-input
                v-model="form.machinecode"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="IP地址:" prop="ipaddress" label-width="115px">
              <el-input
                v-model="form.ipaddress"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="汽车站:" prop="station" label-width="115px">
              <el-input
                v-model="form.station"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安装时间:" prop="settime" label-width="115px">
              <el-input
                v-model="form.settime"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item
              label="商户号:"
              prop="merchantnum"
              label-width="115px"
            >
              <el-input
                v-model="form.merchantnum"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="联系人:"
              prop="contactpeople"
              label-width="115px"
            >
              <el-input
                v-model="form.contactpeople"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="功能:" prop="function" label-width="115px">
              <el-input
                v-model="form.function"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态:" prop="sellstatus" label-width="115px">
              <el-input
                v-model="form.sellstatus"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="厂家:" prop="factory" label-width="115px">
              <el-input
                v-model="form.factory"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工号:" prop="jobnum" label-width="115px">
              <el-input
                v-model="form.jobnum"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="型号:" prop="machinemodel" label-width="115px">
              <el-input
                v-model="form.machinemodel"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="登录密码:"
              prop="loginpassword"
              label-width="115px"
            >
              <el-input
                v-model="form.loginpassword"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="数量:" prop="amount" label-width="115px">
              <el-input
                v-model="form.amount"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="是否允许售票:"
              prop="isallow"
              label-width="115px"
            >
              <p v-if="form.isallow == 1" style="margin-top:0;height:20px">
                可售
              </p>
              <p v-if="form.isallow == 0" style="margin-top:0;height:20px">
                不可售
              </p>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="来源:" prop="source" label-width="115px">
              <el-input
                v-model="form.source"
                placeholder="请输入"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登录状态:" label-width="115px" prop="islogin">
              <p v-if="form.islogin == 1" style="margin-top:0;height:20px">
                已登录
              </p>
              <p v-if="form.islogin == 0" style="margin-top:0;height:20px">
                未登录
              </p>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="备注:" label-width="115px">
              <el-input placeholder="请输入" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="particulars = false">确 定</el-button>
        <el-button @click="particulars = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加自助机配置 -->
    <el-dialog
      :title="title"
      :visible.sync="configuration"
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="18">
            <el-form-item
              label="自助机编号:"
              prop="machinecode"
              label-width="115px"
            >
              <el-input v-model="form.machinecode" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="工号:" prop="jobnum" label-width="115px">
              <el-input v-model="form.jobnum" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item
              label="登录密码:"
              prop="loginpassword"
              label-width="115px"
            >
              <el-input v-model="form.loginpassword" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="当前票号:" prop="dqph" label-width="115px">
              <el-input v-model="form.dqph" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="起票号:" prop="qph" label-width="115px">
              <el-input v-model="form.qph" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="止票号:" prop="zph" label-width="115px">
              <el-input v-model="form.zph" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getSubmitForm">确 定</el-button>
        <el-button @click="configuration = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPage,
  add,
  machine,
  ATMTicket,
  modify,
  getCount
} from "@/api/station/selfService";
export default {
  name: "SelfService",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      //详情弹出框
      particulars: false,
      //自助机配置弹出框
      configuration: false,
      //添加自由自助机参数
      addition: {},
      // 查询参数
      queryParams: {
        pageIndex: 1,
        pageSize: 10
      },
      isallowVal: "",
      loginVal: "",
      //   是否允许售票
      options: [
        {
          value: 1,
          name: "可售"
        },
        {
          value: 0,
          name: "不可售"
        }
      ],
      //   登录状态
      login: [
        {
          value: 1,
          label: "已登录"
        },
        {
          value: 0,
          label: "未登录"
        }
      ],
      // loginlist: [
      //   {
      //     value: 1,
      //     label: "已登录"
      //   },
      //   {
      //     value: 0,
      //     label: "未登录"
      //   }
      // ],
      // 表单参数
      form: {
        islogin: ""
      },
      // 表单校验
      rules: {
        id: [{ required: true, message: "id不能为空", trigger: "blur" }],
        terminacode: [
          { required: true, message: "自助机号不能为空", trigger: "blur" }
        ],
        stationcode: [
          { required: true, message: "汽车站编码不能为空", trigger: "blur" }
        ],
        stationaddress: [
          { required: true, message: "车站地址不能为空", trigger: "blur" }
        ],
        city: [{ required: true, message: "地市不能为空", trigger: "blur" }],
        stationlevel: [
          { required: true, message: "汽车站等级不能为空", trigger: "blur" }
        ],
        machinecode: [
          { required: true, message: "终端号不能为空", trigger: "blur" }
        ],
        ipaddress: [
          { required: true, message: "IP地址不能为空", trigger: "blur" }
        ],
        station: [
          { required: true, message: "汽车站不能为空", trigger: "blur" }
        ],
        settime: [
          { required: true, message: "安装时间不能为空", trigger: "blur" }
        ],
        merchantnum: [
          { required: true, message: "商户号不能为空", trigger: "blur" }
        ],
        contactpeople: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],
        function: [
          { required: true, message: "功能不能为空", trigger: "blur" }
        ],
        sellstatus: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        factory: [{ required: true, message: "厂家不能为空", trigger: "blur" }],
        jobnum: [{ required: true, message: "工号不能为空", trigger: "blur" }],
        machinemodel: [
          { required: true, message: "型号不能为空", trigger: "blur" }
        ],
        loginpassword: [
          { required: true, message: "密码不能为空", trigger: "blur" }
        ],
        amount: [{ required: true, message: "数量不能为空", trigger: "blur" }],
        isallow: [
          { required: true, message: "是否允许不能为空", trigger: "blur" }
        ],
        source: [{ required: true, message: "来源不能为空", trigger: "blur" }],
        islogin: [
          { required: true, message: "登陆状态不能为空", trigger: "blur" }
        ],
        dqph: [{ required: true, message: "当前票号", trigger: "blur" }],
        qph: [{ required: true, message: "起票号不能为空", trigger: "blur" }],
        zph: [{ required: true, message: "止票号不能为空", trigger: "blur" }],
        jobnum: [{ required: true, message: "工号不能为空", trigger: "blur" }],
        loginpassword: [
          { required: true, message: "登录密码不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList(); //自助机列表
  },
  methods: {
    /** 查询自助机列表 */
    getList() {
      getPage(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      // this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        machinecode: undefined,
        terminacode: undefined,
        city: undefined,
        station: undefined,
        stationcode: undefined,
        stationlevel: undefined,
        stationaddress: undefined,
        merchantnum: undefined,
        function: undefined,
        factory: undefined,
        machinemodel: undefined,
        amount: undefined,
        source: undefined,
        ipaddress: undefined,
        settime: undefined,
        contactpeople: undefined,
        sellstatus: undefined,
        jobnum: undefined,
        loginpassword: undefined,
        isallow: undefined,
        islogin: undefined,
        qph: undefined,
        zph: undefined,
        dqph: undefined
      };
      this.isallowVal = undefined;
      this.loginVal = undefined;
      // this.resetForm("form");
      // this.$refs["form"].clearValidate();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageIndex = 1;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加自助机";
      this.$nextTick(() => {
        this.$refs["form"].clearValidate();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.form = row;
      this.title = "修改自助机";
      this.$nextTick(() => {
        this.$refs["form"].clearValidate();
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          add(this.form).then(response => {
            if (response.code == 200) {
              this.open = false;
              this.getList();
            } else {
              this.$message.error(response.msg);
            }
          });
        }
      });
    },
    //详情按钮
    getParticulars(row) {
      this.reset();
      this.particulars = true;
      this.title = "自助机详情";
      this.form = row;
      this.$nextTick(() => {
        this.$refs["form"].clearValidate();
      });
    },
    /** 配置按钮操作 */
    handleDelete(row) {
      this.reset();
      this.addition = row;
      this.title = "添加自助机配置";
      this.configuration = true;
      this.form.machinecode = row.machinecode;
      this.$nextTick(() => {
        this.$refs["form"].clearValidate();
      });
    },
    //  增加配置
    getSubmitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          machine({
            machinecode: this.addition.machinecode,
            globalcode: this.addition.stationcode,
            terminalcode: this.addition.terminacode,
            pwd: this.form.loginpassword,
            userid: this.form.jobnum,
            isallow: this.addition.isallow,
            islogin: this.addition.islogin
          }).then(response => {
            if (response.code == 200) {
            } else {
              this.$message.error(response.msg);
            }
          });
          ATMTicket(this.form).then(response => {
            if (response.code == 200) {
              this.configuration = false;
            } else {
              this.$message.error(response.msg);
            }
          });
        }
      });
    }
  }
};
</script>
<style scoped>
.btn {
  background: none;
  border: none;
  height: 0px;
  color: blue;
  margin-top: -2px;
  margin-left: -15px;
}
</style>
